/*
* SMILParser
*
* Version 1.0
*
* Programmers: Jesse Louderback, Noah Pham, Chad Carpenter, and Marc Hindman
*/
package com.SmilDial;

import comm.SMS_Sender;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class FinalizeMenu extends Activity {
	Bundle SMIL_Bundle;
	Button btnSend;
	Button btnPreview;
	Button btnCancel;
	TextView testTextView;
	EditText inputPhone;
	public static String finalMessage;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.final_menu);

		btnSend = (Button) findViewById(R.id.btnSend);
		btnSend.setEnabled(false);
		btnPreview = (Button) findViewById(R.id.btnPreview);
		btnCancel = (Button) findViewById(R.id.btnCancel);
		testTextView = (TextView) findViewById(R.id.txtViewTest);
		inputPhone = (EditText) findViewById(R.id.inputTextPhone);
		SMIL_Bundle = getIntent().getExtras();

		btnPreview.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(FinalizeMenu.this, ViewMessage.class);

				intent.putExtras(SMIL_Bundle);
				startActivity(intent);
			}
		});

		btnCancel.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent(FinalizeMenu.this, SmilDialActivity.class));
			}
		});
	}

	@Override
	protected void onResume() {
		try {
			if (!finalMessage.equals("")) {
				btnSend.setEnabled(true);
				setSendClickListenter();
			}
		} catch (Exception e) {}
		
		super.onResume();
	}

	private void setSendClickListenter() {
		btnSend.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				String phoneNo = inputPhone.getText().toString();
				if (phoneNo.length() > 0) {
					SMS_Sender send = new SMS_Sender();
					send.sendSMS(getApplicationContext(), phoneNo, finalMessage);	
					startActivity(new Intent(FinalizeMenu.this, SmilDialActivity.class));
				}
			}
		});		
	}
}
